import LoadingComponent from './index.vue';

let $vm;

export default {
    install (vue) {
        if (!$vm) {
            const Loading = vue.extend(LoadingComponent)
            $vm = new Loading({
                el: document.createElement('div')
            });
            document.body.appendChild($vm.$el);
        }

        const loading = {
            show (options) {
                if(typeof options === 'string') {
                    $vm.$el.querySelector('.aui-loading__inner__spiner__tip').innerHTML = msg
                }else if(typeof options === 'object'){
                    $vm.type = options.type? options.type: "";
                    if($vm.type !== 1){ //type==1的时候，是凹凸租车的logo，此logo带白色底，所以加上文案提示不适合
                        $vm.$el.querySelector('.aui-loading__inner__spiner__tip').innerHTML = options.msg? options.msg: "";
                    }
                }

                $vm.onShow();
            },
            hide () {
                $vm.onHide();
            }
        }

        if (!vue.$aui) {
            vue.$aui = {
                loading
            }
        } else {
            vue.$aui.loading = loading
        }

        vue.mixin({
            created: function () {
                this.$aui = vue.$aui
            }
        });
    }
}
